home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / PROGRAMMING / DESKLIBC / SOURCES.ZIP / DeskLib / !DLSources / Libraries / Icon / c / SetText < prev    next >
Text File  |  1995-07-08  |  2KB  |  64 lines

  1. /*
  2.     ####             #    #     # #
  3.     #   #            #    #       #          The FreeWare C library for 
  4.     #   #  ##   ###  #  # #     # ###             RISC OS machines
  5.     #   # #  # #     # #  #     # #  #   ___________________________________
  6.     #   # ####  ###  ##   #     # #  #                                      
  7.     #   # #        # # #  #     # #  #    Please refer to the accompanying
  8.     ####   ### ####  #  # ##### # ###    documentation for conditions of use
  9.     ________________________________________________________________________
  10.  
  11.     File:    Icon.SetText.c
  12.     Author:  Copyright © 1992, 1993, 1994 Jason Williams
  13.     Version: 1.01 (12 Mar 1994)
  14.     Purpose: 'Print' a string into an icon's text buffer.
  15. */
  16.  
  17. #include <string.h>
  18.  
  19. #include "DeskLib:Wimp.h"
  20. #include "DeskLib:WimpSWIs.h"
  21. #include "DeskLib:Coord.h"
  22. #include "DeskLib:Icon.h"
  23.  
  24.  
  25.  
  26. extern void Icon_SetText(window_handle w, icon_handle i, char *text)
  27. /*
  28.  * Copies the text string into the icon's indirected string buffer (and redraws)
  29.  * If unable to set the text (incorrect icon type), it returns quietly
  30.  * If text passed in is a NULL pointer, sets icon text to " "
  31.  */
  32. {
  33.   icon_block  istate;
  34.   char        temp[2] = " ";
  35.   caret_block caret;
  36.   int         len;
  37.  
  38.   if (text == NULL)
  39.     text = temp;
  40.  
  41.   Wimp_GetIconState(w, i, &istate);
  42.   if (istate.flags.value & (icon_TEXT | icon_INDIRECTED))
  43.   {
  44.     /* Indirected text icon, so set text field - ensure no buffer overflow */
  45.     strncpy(istate.data.indirecttext.buffer, text,
  46.               istate.data.indirecttext.bufflen - 1);
  47.     istate.data.indirecttext.buffer[istate.data.indirecttext.bufflen-1] = 0;
  48.  
  49.     /* Ensure caret isn't beyond end of text */
  50.     Wimp_GetCaretPosition( &caret );
  51.     if ( caret.window == w && caret.icon == i )
  52.     {
  53.       len = strlen( istate.data.indirecttext.buffer );
  54.       if ( caret.index > len )
  55.       {
  56.         caret.index = len;
  57.         Wimp_SetCaretPosition( &caret );
  58.       }
  59.     }
  60.     
  61.     Wimp_SetIconState(w, i, 0, 0);
  62.   }
  63. }
  64.